991B - Getting an A - CodeForces Solution


greedy sortings *900

Please click on ads to support us..

Python Code:

n = int(input())
sum = 0

ls = list(map(int, input().split()))

for i in range(0,n):
    sum += ls[i]
ls.sort()
avg = sum/n
ans = 0

if(avg >= 4.5):
    print(0)
else:
    for i in range(0,n):
        if(avg >= 4.5):
            break
        else:
            sum += (5- ls[i])
            ls[i] = 5
            avg = sum/n
            ans+=1

    print(ans)

    
    

C++ Code:

#include <iostream>
#include "vector"
#include "cmath"
#include "iomanip"
#include "string"
#include "list"
#include "algorithm"
#include "set"

#include "map"
#include "numeric"
using namespace  std;
long long mod = 1e9 + 7;
#define ll long long
#define ld long double
#define s set<int>
#define pair pair<int,int>
const int  SIZE = 1e6+1;
const ld e = 1e-12;
int convert(long long n) {
    int dec = 0, i = 0, rem;

    while (n!=0) {
        rem = n % 10;
        n /= 10;
        dec += rem * pow(2, i);
        ++i;
    }

    return dec;
}
ll gcd(ll a, ll b)
{
    if (a * b == 0) return a + b;
    if (a < b)
        return gcd(a,b%a);
    else
        return gcd(a%b,b);

}
void fastio()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
}
ll fact(ll a)
{
    ll sum = 1;
    for (int i = 2; i <= a; i++)
    {
        sum *= i;
    }
    return sum;

}

int qpow(int a,int b) {
    int r = 1;
    while (b) {
        if (b & 1)r = r % mod * a % mod;
        a = a % mod * a % mod;
        b >>= 1;
    }
    return r;
}


bool comp(pair a, pair b)
{
    return (a.first < b.first);
}

int main() {
    fastio();
    int n;
    cin >> n;
    vector<ld>a(n);
    ld sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int count = 0;
    sort(a.begin(),a.end());
    for (int i = 0; i < n; i++) {
        if (sum / n >= 4.5) {
            break;
        }
        if (a[i] != 5.0) {
            sum += fabs(a[i] - 5.0);
            count++;
        }
       // cout << sum / n << '\n';
    }
    cout << count << " ";
}




















Comments

Submit
0 Comments
More Questions

305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes
1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments
1428B - Belted Rooms
519B - A and B and Compilation Errors
1152B - Neko Performs Cat Furrier Transform
1411A - In-game Chat
119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words